﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    ShopDataContext dc = new ShopDataContext();

    protected void Page_Load(object sender, EventArgs e)
    {
        if(Session["UserID"] == null)
            Session["UserID"] = Guid.NewGuid().ToString();
        if(!IsPostBack)
        {
            var query = (from od in dc.OrderDetails
                        join o in dc.Orders on od.oId equals o.oId
                        join p in dc.Products on od.pId equals p.pId
                        group od by od.pId into g
                        orderby g.Sum(od => od.oQuantity) descending
                        from p in dc.Products
                        where p.pId == g.Key
                        select p).Take(5);

            ListView1.DataSource = query;
            ListView1.DataBind();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        
    }
   
}